package com.example.tests;

import java.util.Iterator;
import java.util.List;
import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.Select;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.util.UserHelper;

public class AddFileInfoTest {
	private WebDriver driver;
	private StringBuffer verificationErrors = new StringBuffer();
	@BeforeMethod
	public void setUp() throws Exception {
		driver = UserHelper.getDriver();
		driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
	}
	@Test
	public void testUntitled() throws Exception {
		driver.get(UserHelper.rb.getString("url"));
		driver.findElement(By.id("file_desc_normal")).click();
		
		long time=System.currentTimeMillis();
		String miaoshu=time+"??????????";
		//????????????DIV
		System.out.println("file_desc_edit:  "+driver.findElement(By.id("file_desc_edit")).getText());
//		System.out.println("file_desc_normal :"+driver.findElement(By.id("file_desc_normal")).getText());
		WebElement ele=driver.findElement(By.id("file_desc_edit"));
		for(int i=0;i<30;i++){
			ele.sendKeys(Keys.BACK_SPACE);
		}
		driver.findElement(By.id("file_desc_edit")).sendKeys(miaoshu);
		driver.findElement(By.id("c_content")).click();
		System.out.println("????:"+miaoshu);
		Assert.assertTrue(driver.findElement(By.id("file_desc_normal")).getText().contains(miaoshu));
	}

	@AfterMethod
	public void tearDown() throws Exception {
		//Thread.sleep(10000);
		//driver.quit();
		String verificationErrorString = verificationErrors.toString();
		if (!"".equals(verificationErrorString)) {
			Assert.fail(verificationErrorString);
		}
	}

	private boolean isElementPresent(By by) {
		try {
			driver.findElement(by);
			return true;
		} catch (NoSuchElementException e) {
			return false;
		}
	}
}
